package com.cf.base.http.interceptor;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import retrofit2.internal.EverythingIsNonNull;

/**
 * @author yangji
 */
@EverythingIsNonNull
public class StatisticsInterceptor implements Interceptor {

    private final static String STATISTICS_HTTP = "STATISTICS_HTTP";
    private final static String STATISTICS_FILE = "STATISTICS_FILE";

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response = chain.proceed(chain.request());
        if (response.isSuccessful()) {
            RequestBody requestBody = request.body();
            long requestLength = requestBody == null ? 0 : requestBody.contentLength();
            ResponseBody responseBody = response.body();
            long responseLength = responseBody == null ? 0 : responseBody.contentLength();

            long sumLength = requestLength + responseLength;

            if (sumLength == 0) {
                return response;
            }
            return response;
        }
        return response;
    }
}
